home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / driver.h < prev    next >
C/C++ Source or Header  |  2000-05-10  |  13KB  |  468 lines

  1. #ifndef DRIVER_H
  2. #define DRIVER_H
  3.  
  4. #include "osd_cpu.h"
  5. #include "memory.h"
  6. #include "osdepend.h"
  7. #include "mame.h"
  8. #include "common.h"
  9. #include "drawgfx.h"
  10. #include "palette.h"
  11. #include "cpuintrf.h"
  12. #include "sndintrf.h"
  13. #include "input.h"
  14. #include "inptport.h"
  15. #include "usrintrf.h"
  16. #include "cheat.h"
  17. #include "tilemap.h"
  18. #include "sprite.h"
  19. #include "gfxobj.h"
  20. #include "profiler.h"
  21.  
  22. #ifdef MAME_NET
  23. #include "network.h"
  24. #endif /* MAME_NET */
  25.  
  26. struct MachineCPU
  27. {
  28.     int cpu_type;    /* see #defines below. */
  29.     int cpu_clock;    /* in Hertz */
  30.     const struct MemoryReadAddress *memory_read;
  31.     const struct MemoryWriteAddress *memory_write;
  32.     const struct IOReadPort *port_read;
  33.     const struct IOWritePort *port_write;
  34.     int (*vblank_interrupt)(void);
  35.     int vblank_interrupts_per_frame;    /* usually 1 */
  36. /* use this for interrupts which are not tied to vblank     */
  37. /* usually frequency in Hz, but if you need                 */
  38. /* greater precision you can give the period in nanoseconds */
  39.     int (*timed_interrupt)(void);
  40.     int timed_interrupts_per_second;
  41. /* pointer to a parameter to pass to the CPU cores reset function */
  42.     void *reset_param;
  43. };
  44.  
  45. enum
  46. {
  47.     CPU_DUMMY,
  48. #if (HAS_Z80)
  49.     CPU_Z80,
  50. #endif
  51. #if (HAS_Z80GB)
  52.     CPU_Z80GB,
  53. #endif
  54. #if (HAS_8080)
  55.     CPU_8080,
  56. #endif
  57. #if (HAS_8085A)
  58.     CPU_8085A,
  59. #endif
  60. #if (HAS_M6502)
  61.     CPU_M6502,
  62. #endif
  63. #if (HAS_M65C02)
  64.     CPU_M65C02,
  65. #endif
  66. #if (HAS_M65SC02)
  67.     CPU_M65SC02,
  68. #endif
  69. #if (HAS_M65CE02)
  70.     CPU_M65CE02,
  71. #endif
  72. #if (HAS_M6509)
  73.     CPU_M6509,
  74. #endif
  75. #if (HAS_M6510)
  76.     CPU_M6510,
  77. #endif
  78. #if (HAS_M6510T)
  79.     CPU_M6510T,
  80. #endif
  81. #if (HAS_M7501)
  82.     CPU_M7501,
  83. #endif
  84. #if (HAS_M8502)
  85.     CPU_M8502,
  86. #endif
  87. #if (HAS_N2A03)
  88.     CPU_N2A03,
  89. #endif
  90. #if (HAS_M4510)
  91.     CPU_M4510,
  92. #endif
  93. #if (HAS_H6280)
  94.     CPU_H6280,
  95. #endif
  96. #if (HAS_I86)
  97.     CPU_I86,
  98. #endif
  99. #if (HAS_I88)
  100.     CPU_I88,
  101. #endif
  102. #if (HAS_I186)
  103.     CPU_I186,
  104. #endif
  105. #if (HAS_I188)
  106.     CPU_I188,
  107. #endif
  108. #if (HAS_I286)
  109.     CPU_I286,
  110. #endif
  111. #if (HAS_V20)
  112.     CPU_V20,
  113. #endif
  114. #if (HAS_V30)
  115.     CPU_V30,
  116. #endif
  117. #if (HAS_V33)
  118.     CPU_V33,
  119. #endif
  120. #if (HAS_I8035)
  121.     CPU_I8035,        /* same as CPU_I8039 */
  122. #endif
  123. #if (HAS_I8039)
  124.     CPU_I8039,
  125. #endif
  126. #if (HAS_I8048)
  127.     CPU_I8048,        /* same as CPU_I8039 */
  128. #endif
  129. #if (HAS_N7751)
  130.     CPU_N7751,        /* same as CPU_I8039 */
  131. #endif
  132. #if (HAS_M6800)
  133.     CPU_M6800,        /* same as CPU_M6802/CPU_M6808 */
  134. #endif
  135. #if (HAS_M6801)
  136.     CPU_M6801,        /* same as CPU_M6803 */
  137. #endif
  138. #if (HAS_M6802)
  139.     CPU_M6802,        /* same as CPU_M6800/CPU_M6808 */
  140. #endif
  141. #if (HAS_M6803)
  142.     CPU_M6803,        /* same as CPU_M6801 */
  143. #endif
  144. #if (HAS_M6808)
  145.     CPU_M6808,        /* same as CPU_M6800/CPU_M6802 */
  146. #endif
  147. #if (HAS_HD63701)
  148.     CPU_HD63701,    /* 6808 with some additional opcodes */
  149. #endif
  150. #if (HAS_NSC8105)
  151.     CPU_NSC8105,    /* same(?) as CPU_M6802(?) with scrambled opcodes. There is at least one new opcode. */
  152. #endif
  153. #if (HAS_M6805)
  154.     CPU_M6805,
  155. #endif
  156. #if (HAS_M68705)
  157.     CPU_M68705,     /* same as CPU_M6805 */
  158. #endif
  159. #if (HAS_HD63705)
  160.     CPU_HD63705,    /* M6805 family but larger address space, different stack size */
  161. #endif
  162. #if (HAS_HD6309)
  163.     CPU_HD6309,        /* same as CPU_M6809 (actually it's not 100% compatible) */
  164. #endif
  165. #if (HAS_M6809)
  166.     CPU_M6809,
  167. #endif
  168. #if (HAS_KONAMI)
  169.     CPU_KONAMI,
  170. #endif
  171. #if (HAS_M68000)
  172.     CPU_M68000,
  173. #endif
  174. #if (HAS_M68010)
  175.     CPU_M68010,
  176. #endif
  177. #if (HAS_M68EC020)
  178.     CPU_M68EC020,
  179. #endif
  180. #if (HAS_M68020)
  181.     CPU_M68020,
  182. #endif
  183. #if (HAS_T11)
  184.     CPU_T11,
  185. #endif
  186. #if (HAS_S2650)
  187.     CPU_S2650,
  188. #endif
  189. #if (HAS_TMS34010)
  190.     CPU_TMS34010,
  191. #endif
  192. #if (HAS_TMS9900)
  193.     CPU_TMS9900,
  194. #endif
  195. #if (HAS_TMS9940)
  196.     CPU_TMS9940,
  197. #endif
  198. #if (HAS_TMS9980)
  199.     CPU_TMS9980,
  200. #endif
  201. #if (HAS_TMS9985)
  202.     CPU_TMS9985,
  203. #endif
  204. #if (HAS_TMS9989)
  205.     CPU_TMS9989,
  206. #endif
  207. #if (HAS_TMS9995)
  208.     CPU_TMS9995,
  209. #endif
  210. #if (HAS_TMS99105A)
  211.     CPU_TMS99105A,
  212. #endif
  213. #if (HAS_TMS99110A)
  214.     CPU_TMS99110A,
  215. #endif
  216. #if (HAS_Z8000)
  217.     CPU_Z8000,
  218. #endif
  219. #if (HAS_TMS320C10)
  220.     CPU_TMS320C10,
  221. #endif
  222. #if (HAS_CCPU)
  223.     CPU_CCPU,
  224. #endif
  225. #if (HAS_PDP1)
  226.     CPU_PDP1,
  227. #endif
  228. #if (HAS_ADSP2100)
  229.     CPU_ADSP2100,
  230. #endif
  231. #if (HAS_MIPS)
  232.     CPU_MIPS,
  233. #endif
  234.     CPU_COUNT
  235. };
  236.  
  237. /* set this if the CPU is used as a slave for audio. It will not be emulated if */
  238. /* sound is disabled, therefore speeding up a lot the emulation. */
  239. #define CPU_AUDIO_CPU 0x8000
  240.  
  241. /* the Z80 can be wired to use 16 bit addressing for I/O ports */
  242. #define CPU_16BIT_PORT 0x4000
  243.  
  244. #define CPU_FLAGS_MASK 0xff00
  245.  
  246.  
  247. #define MAX_CPU 8    /* MAX_CPU is the maximum number of CPUs which cpuintrf.c */
  248.                     /* can run at the same time. Currently, 8 is enough. */
  249.  
  250.  
  251. #define MAX_SOUND 5    /* MAX_SOUND is the maximum number of sound subsystems */
  252.                     /* which can run at the same time. Currently, 5 is enough. */
  253.  
  254.  
  255.  
  256. struct MachineDriver
  257. {
  258.     /* basic machine hardware */
  259.     struct MachineCPU cpu[MAX_CPU];
  260.     float frames_per_second;
  261.     int vblank_duration;    /* in microseconds - see description below */
  262.     int cpu_slices_per_frame;    /* for multicpu games. 1 is the minimum, meaning */
  263.                                 /* that each CPU runs for the whole video frame */
  264.                                 /* before giving control to the others. The higher */
  265.                                 /* this setting, the more closely CPUs are interleaved */
  266.                                 /* and therefore the more accurate the emulation is. */
  267.                                 /* However, an higher setting also means slower */
  268.                                 /* performance. */
  269.     void (*init_machine)(void);
  270. #ifdef MESS
  271.     void (*stop_machine)(void); /* needed for MESS */
  272. #endif
  273.  
  274.     /* video hardware */
  275.     int screen_width,screen_height;
  276.     struct rectangle visible_area;
  277.     struct GfxDecodeInfo *gfxdecodeinfo;
  278.     unsigned int total_colors;    /* palette is 3*total_colors bytes long */
  279.     unsigned int color_table_len;    /* length in shorts of the color lookup table */
  280.     void (*vh_init_palette)(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom);
  281.  
  282.     int video_attributes;    /* ASG 081897 */
  283.  
  284.     void (*vh_eof_callback)(void);    /* called every frame after osd_update_video_and_audio() */
  285.                                     /* This is useful when there are operations that need */
  286.                                     /* to be performed every frame regardless of frameskip, */
  287.                                     /* e.g. sprite buffering or collision detection. */
  288.     int (*vh_start)(void);
  289.     void (*vh_stop)(void);
  290.     void (*vh_update)(struct osd_bitmap *bitmap,int full_refresh);
  291.  
  292.     /* sound hardware */
  293.     int sound_attributes;
  294.     int obsolete1;
  295.     int obsolete2;
  296.     int obsolete3;
  297.     struct MachineSound sound[MAX_SOUND];
  298.  
  299.     /*
  300.        use this to manage nvram/eeprom/cmos/etc.
  301.        It is called before the emulation starts and after it ends. Note that it is
  302.        NOT called when the game is reset, since it is not needed.
  303.        file == 0, read_or_write == 0 -> first time the game is run, initialize nvram
  304.        file != 0, read_or_write == 0 -> load nvram from disk
  305.        file == 0, read_or_write != 0 -> not allowed
  306.        file != 0, read_or_write != 0 -> save nvram to disk
  307.      */
  308.     void (*nvram_handler)(void *file,int read_or_write);
  309. };
  310.  
  311.  
  312.  
  313. /* VBlank is the period when the video beam is outside of the visible area and */
  314. /* returns from the bottom to the top of the screen to prepare for a new video frame. */
  315. /* VBlank duration is an important factor in how the game renders itself. MAME */
  316. /* generates the vblank_interrupt, lets the game run for vblank_duration microseconds, */
  317. /* and then updates the screen. This faithfully reproduces the behaviour of the real */
  318. /* hardware. In many cases, the game does video related operations both in its vblank */
  319. /* interrupt, and in the normal game code; it is therefore important to set up */
  320. /* vblank_duration accurately to have everything properly in sync. An example of this */
  321. /* is Commando: if you set vblank_duration to 0, therefore redrawing the screen BEFORE */
  322. /* the vblank interrupt is executed, sprites will be misaligned when the screen scrolls. */
  323.  
  324. /* Here are some predefined, TOTALLY ARBITRARY values for vblank_duration, which should */
  325. /* be OK for most cases. I have NO IDEA how accurate they are compared to the real */
  326. /* hardware, they could be completely wrong. */
  327. #define DEFAULT_60HZ_VBLANK_DURATION 0
  328. #define DEFAULT_30HZ_VBLANK_DURATION 0
  329. /* If you use IPT_VBLANK, you need a duration different from 0. */
  330. #define DEFAULT_REAL_60HZ_VBLANK_DURATION 2500
  331. #define DEFAULT_REAL_30HZ_VBLANK_DURATION 2500
  332.  
  333.  
  334.  
  335. /* flags for video_attributes */
  336.  
  337. /* bit 0 of the video attributes indicates raster or vector video hardware */
  338. #define    VIDEO_TYPE_RASTER            0x0000
  339. #define    VIDEO_TYPE_VECTOR            0x0001
  340.  
  341. /* bit 1 of the video attributes indicates whether or not dirty rectangles will work */
  342. #define    VIDEO_SUPPORTS_DIRTY        0x0002
  343.  
  344. /* bit 2 of the video attributes indicates whether or not the driver modifies the palette */
  345. #define    VIDEO_MODIFIES_PALETTE    0x0004
  346.  
  347. /* ASG 980417 - added: */
  348. /* bit 4 of the video attributes indicates that the driver wants its refresh after */
  349. /*       the VBLANK instead of before. */
  350. #define    VIDEO_UPDATE_BEFORE_VBLANK    0x0000
  351. #define    VIDEO_UPDATE_AFTER_VBLANK    0x0010
  352.  
  353. /* In most cases we assume pixels are square (1:1 aspect ratio) but some games need */
  354. /* different proportions, e.g. 1:2 for Blasteroids */
  355. #define VIDEO_PIXEL_ASPECT_RATIO_MASK 0x0020
  356. #define VIDEO_PIXEL_ASPECT_RATIO_1_1 0x0000
  357. #define VIDEO_PIXEL_ASPECT_RATIO_1_2 0x0020
  358.  
  359. #define VIDEO_DUAL_MONITOR 0x0040
  360.  
  361. /* Mish 181099:  See comments in vidhrdw/generic.c for details */
  362. #define VIDEO_BUFFERS_SPRITERAM 0x0080
  363.  
  364. /* flags for sound_attributes */
  365. #define    SOUND_SUPPORTS_STEREO        0x0001
  366.  
  367.  
  368.  
  369. struct GameDriver
  370. {
  371.     const char *source_file;    /* set this to __FILE__ */
  372.     const struct GameDriver *clone_of;    /* if this is a clone, point to */
  373.                                         /* the main version of the game */
  374.     const char *name;
  375.     const char *description;
  376.     const char *year;
  377.     const char *manufacturer;
  378.     const struct MachineDriver *drv;
  379.     const struct InputPortTiny *input_ports;
  380.     void (*driver_init)(void);    /* optional function to be called during initialization */
  381.                                 /* This is called ONCE, unlike Machine->init_machine */
  382.                                 /* which is called every time the game is reset. */
  383.  
  384.     const struct RomModule *rom;
  385. #ifdef MESS
  386.     const struct IODevice *dev;
  387. #endif
  388.  
  389.     UINT32 flags;    /* orientation and other flags; see defines below */
  390. };
  391.  
  392.  
  393. /* values for the flags field */
  394.  
  395. #define ORIENTATION_MASK            0x0007
  396. #define    ORIENTATION_FLIP_X            0x0001    /* mirror everything in the X direction */
  397. #define    ORIENTATION_FLIP_Y            0x0002    /* mirror everything in the Y direction */
  398. #define ORIENTATION_SWAP_XY            0x0004    /* mirror along the top-left/bottom-right diagonal */
  399.  
  400. #define GAME_NOT_WORKING            0x0008
  401. #define GAME_WRONG_COLORS            0x0010    /* colors are totally wrong */
  402. #define GAME_IMPERFECT_COLORS        0x0020    /* colors are not 100% accurate, but close */
  403. #define GAME_NO_SOUND                0x0040    /* sound is missing */
  404. #define GAME_IMPERFECT_SOUND        0x0080    /* sound is known to be wrong */
  405. #define    GAME_REQUIRES_16BIT            0x0100    /* cannot fit in 256 colors */
  406. #define GAME_NO_COCKTAIL            0x0200    /* screen flip support is missing */
  407. #define GAME_UNEMULATED_PROTECTION    0x0400    /* game's protection not fully emulated */
  408. #define NOT_A_DRIVER                0x4000    /* set by the fake "root" driver_ and by "containers" */
  409.                                             /* e.g. driver_neogeo. */
  410. #ifdef MESS
  411. #define GAME_COMPUTER    0x8000            /* Driver is a computer (needs full keyboard) */
  412. #define GAME_ALIAS        NOT_A_DRIVER    /* Driver is only an alias for an existing model */
  413. #endif
  414.  
  415.  
  416. #define GAME(YEAR,NAME,PARENT,MACHINE,INPUT,INIT,MONITOR,COMPANY,FULLNAME)    \
  417. extern struct GameDriver driver_##PARENT;    \
  418. struct GameDriver driver_##NAME =            \
  419. {                                            \
  420.     __FILE__,                                \
  421.     &driver_##PARENT,                        \
  422.     #NAME,                                    \
  423.     FULLNAME,                                \
  424.     #YEAR,                                    \
  425.     COMPANY,                                \
  426.     &machine_driver_##MACHINE,                \
  427.     input_ports_##INPUT,                    \
  428.     init_##INIT,                            \
  429.     rom_##NAME,                                \
  430.     MONITOR,                                \
  431. };
  432.  
  433. #define GAMEX(YEAR,NAME,PARENT,MACHINE,INPUT,INIT,MONITOR,COMPANY,FULLNAME,FLAGS)    \
  434. extern struct GameDriver driver_##PARENT;    \
  435. struct GameDriver driver_##NAME =            \
  436. {                                            \
  437.     __FILE__,                                \
  438.     &driver_##PARENT,                        \
  439.     #NAME,                                    \
  440.     FULLNAME,                                \
  441.     #YEAR,                                    \
  442.     COMPANY,                                \
  443.     &machine_driver_##MACHINE,                \
  444.     input_ports_##INPUT,                    \
  445.     init_##INIT,                            \
  446.     rom_##NAME,                                \
  447.     (MONITOR)|(FLAGS),                        \
  448. };
  449.  
  450.  
  451. /* monitor parameters to be used with the GAME() macro */
  452. #define    ROT0    0x0000
  453. #define    ROT90    (ORIENTATION_SWAP_XY|ORIENTATION_FLIP_X)    /* rotate clockwise 90 degrees */
  454. #define    ROT180    (ORIENTATION_FLIP_X|ORIENTATION_FLIP_Y)        /* rotate 180 degrees */
  455. #define    ROT270    (ORIENTATION_SWAP_XY|ORIENTATION_FLIP_Y)    /* rotate counter-clockwise 90 degrees */
  456. #define    ROT0_16BIT        (ROT0|GAME_REQUIRES_16BIT)
  457. #define    ROT90_16BIT        (ROT90|GAME_REQUIRES_16BIT)
  458. #define    ROT180_16BIT    (ROT180|GAME_REQUIRES_16BIT)
  459. #define    ROT270_16BIT    (ROT270|GAME_REQUIRES_16BIT)
  460.  
  461. /* this allows to leave the INIT field empty in the GAME() macro call */
  462. #define init_0 0
  463.  
  464.  
  465. extern const struct GameDriver *drivers[];
  466.  
  467. #endif
  468.